import time

from PySide6.QtWidgets import QApplication, QMessageBox, QRadioButton, QCheckBox
from PySide6.QtUiTools import QUiLoader

# 在QApplication之前先实例化
uiLoader = QUiLoader()

class Stats:

    def __init__(self):
        # 再加载界面
        self.ui = uiLoader.load('ui/ui_qcheckbox.ui')
        self.ui.pushButton.clicked.connect(self.demo_1)
        self.ui.checkBox.toggled.connect(self.demo_2)  # 点击单选按钮时出发方法
        self.ui.checkBox_2.setChecked(True)  # 设置为选中状态
        self.ui.checkBox_2.toggled.connect(self.demo_3)  # 点击单选按钮时出发方法

    def demo_1(self):
        checked_button = self.ui.groupBox.findChildren(QCheckBox)
        for button in checked_button:
            if button.isChecked():
                self.ui.label.setText(f"选取了：{button.text()}")

    def demo_2(self):
        self.ui.label.setText(f"点击了demo_2_a按钮")

    def demo_3(self):
        self.ui.label.setText(f"点击了demo_3_b按钮")

app = QApplication([])
stats = Stats()
stats.ui.show()
app.exec() # PySide6 是 exec 而不是 exec_